package com.anglireports.report.bean.report;

import com.alibaba.fastjson.JSONObject;
import com.anglireports.report.bean.base.BaseBean;
import com.anglireports.report.data.campusPage.CampusDataUtil;
import com.anglireports.report.response.util.CommonUtils;

import java.util.List;

/**
 * 报告-学生情绪
 * @author lvjilei
 * @ceateTime 2019/3/25.
 */
public class Emotion extends BaseBean{
    /**
     * 侦测到情绪为「中性」的次数。
     */
    private Integer normal;

    /**
     * 侦测到情绪为「正面」的次数。
     */
    private Integer passion;

    /**
     * 侦测到情绪为「负面」的次数。
     */
    private Integer upset;

    /**
     * 侦测到情绪为「疑惑」的次数。
     */
    private Integer question;


    public Emotion() {
    }

    public Emotion(Integer normal, Integer passion, Integer upset, Integer question) {
        this.normal = normal;
        this.passion = passion;
        this.upset = upset;
        this.question = question;
    }

    public Integer getNormal() {
        return normal;
    }

    public void setNormal(Integer normal) {
        this.normal = normal;
    }

    public Integer getPassion() {
        return passion;
    }

    public void setPassion(Integer passion) {
        this.passion = passion;
    }

    public Integer getUpset() {
        return upset;
    }

    public void setUpset(Integer upset) {
        this.upset = upset;
    }

    public Integer getQuestion() {
        return question;
    }

    public void setQuestion(Integer question) {
        this.question = question;
    }

    /**
     * 根据计算规则计算出情绪指数.
     * @return
     */
    public Float getEmotionData(){
        return CommonUtils.getNum( (0 * upset + 33 * question + 66 * normal + 100 * passion)/
                (float)(upset + question + normal + passion), "0.0");
    }

    /**
     * 根据计算规则计算出正面情绪指数.
     * @return
     */
    public Float getActiveEmotionData(){
        return CommonUtils.getNum( (float)passion / (upset + question + normal + passion), "0.0");
    }

    public static Emotion getEmotionAvg(List<Emotion> list){
        Emotion emotion = new Emotion();
        Integer upset = 0;
        Integer qustion = 0;
        Integer normal = 0;
        Integer passion = 0;

        for (Emotion e : list){
            upset += e.getUpset();
            qustion += e.getQuestion();
            normal += e.getNormal();
            passion += e.getPassion();
        }

        emotion.setUpset(upset/list.size());
        emotion.setQuestion(qustion/list.size());
        emotion.setNormal(normal/list.size());
        emotion.setPassion(passion/list.size());
        return emotion;
    }

    public Emotion megreEmotion(Emotion megreEmotion){
        this.setNormal(this.getNormal() + megreEmotion.getNormal());
        this.setPassion(this.getPassion() + megreEmotion.getPassion());
        this.setQuestion(this.getQuestion() + megreEmotion.getQuestion());
        this.setUpset(this.getUpset() + megreEmotion.getUpset());
        return this;
    }

    //中性
    public Float getNormalPercent(){
        return CommonUtils.getNum( (float)normal / (upset + question + normal + passion)*100, "0.0");
    }
    //正面
    public Float getPassionPercent(){
        return CommonUtils.getNum( (float)passion / (upset + question + normal + passion)*100, "0.0");
    }
    //疑问
    public Float getQuestionPercent(){
        return CommonUtils.getNum( (float)question / (upset + question + normal + passion)*100, "0.0");
    }
    //负面
    public Float getUpsetPercent(){
        return CommonUtils.getNum( (float)upset / (upset + question + normal + passion)*100, "0.0");
    }

    public static void main(String[] args){

        Emotion emotion = new Emotion(1011, 1566 ,22,789);
        System.out.println(emotion.getNormalPercent());
        System.out.println(emotion.getPassionPercent());
        System.out.println(emotion.getUpsetPercent());
        System.out.println(emotion.getQuestionPercent());

    }

}
